package mysql

import (
	"doc-manage/docrpc/docrpc"
	"gorm.io/gorm"
)

type Doctor struct {
	gorm.Model
	Name string `gorm:"type:varchar(30);not null;comment:医生姓名"`
	Asc  string `gorm:"type:varchar(30);not null;comment:医生院区"`
	Desc string `gorm:"type:varchar(30);not null;comment:医生简介"`
}

func (d *Doctor) DoctorAdd(db *gorm.DB) error {
	return db.Debug().Create(d).Error
}

func (d *Doctor) DoctorUpdate(db *gorm.DB, id int64) error {
	return db.Debug().Where("id = ?", id).Updates(d).Error
}

func (d *Doctor) DoctorShow(db *gorm.DB, id int64) error {
	return db.Debug().Where("id = ?", id).First(d).Error
}

func DoctorList(db *gorm.DB) ([]*docrpc.DoctorList, error) {
	var list []*docrpc.DoctorList
	err2 := db.Debug().Model(&Doctor{}).
		Select("doctors.id as doctor_id",
			"name",
			"asc",
			"desc").Find(&list).Error
	return list, err2
}
